package chaowan.Service.impl;

import chaowan.Mapper.GoodsMapper;
import chaowan.Service.GoodsService;
import chaowan.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> findAll() {
        return goodsMapper.selectAll();
    }

    @Override
    public Goods findById(Long gid) {
        return goodsMapper.selectById(gid);
    }

    @Override
    public Goods save(Goods goods) {
        goodsMapper.insert(goods);
        return goods;
    }

    @Override
    public Goods update(Goods goods) {
        goodsMapper.update(goods);
        return goods;
    }

    @Override
    public void deleteById(Long gid) {
        goodsMapper.deleteById(gid);
    }

    @Override
    public List<Goods> searchByKeyword(String keyword) {
        return goodsMapper.searchByKeyword(keyword);
    }

    @Override
    public List<Goods> findByCategoryId(Long cid) {
        return goodsMapper.findByCategoryId(cid);
    }

}